package com.open.capacity.reimburse.controller;

import java.util.List;
import java.util.Map;

import com.open.capacity.commons.Result;
import com.open.capacity.reimburse.entity.BaseBgtEco;
import com.open.capacity.reimburse.entity.BasePayItemFormSelect;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.BasePayItemForm;
import com.open.capacity.reimburse.service.BasePayItemFormService;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 支出事项-表单标准项
 *
 * @author
 * @email
 * @date 2023-11-01 19:00:37
 */
@RestController
@RequestMapping("basepayitemforms")
@Api(tags = "支出事项-表单标准项")
public class BasePayItemFormController {

    @Autowired
    private BasePayItemFormService basePayItemFormService;

    /**
     * 列表
     */
    @RequestMapping("/findByPayitemId")
    @PreAuthorize("hasAnyAuthority('base_pay_item_bgt_eco:basepayitembgteco:list')")
    public Result findByPayitemId(String payitemId) {
        List<BasePayItemForm> list = basePayItemFormService.findByPayitemId(payitemId);
        return Result.succeed(list, "success");
    }

    /**
     * 列表
     */
    @RequestMapping("/findByPayitemIds")
    @PreAuthorize("hasAnyAuthority('base_pay_item_bgt_eco:basepayitembgteco:list')")
    public Result findByPayitemIds(String payitemIds) {
        Map<String, List<BasePayItemForm>> map = basePayItemFormService.findByPayitemIds(payitemIds);
        return Result.succeed(map, "success");
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('base_pay_item_form:basepayitemform:list')")
    public Result findById(String id) {
        return Result.succeed(basePayItemFormService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('base_pay_item_form:basepayitemform:save')")
    public Result save(@RequestBody @Valid BasePayItemForm basePayItemForm, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            basePayItemFormService.save(basePayItemForm);
        } else {
            basePayItemForm.setId(keyValue);
            basePayItemFormService.update(basePayItemForm);
        }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('base_pay_item_form:basepayitemform:delete')")
    public Result delete(@PathVariable String id) {
        basePayItemFormService.delete(id);
        return Result.succeed("删除成功");
    }

    /**
     * 下拉选项查询
     */
    @RequestMapping("/findSelectByFormId")
    @PreAuthorize("hasAnyAuthority('base_pay_item_bgt_eco:basepayitembgteco:list')")
    public Result findSelectByFormId(String formId, String keyword) {
        List<BasePayItemFormSelect> list = basePayItemFormService.findSelectByFormId(formId, keyword);
        return Result.succeed(list, "success");
    }


    /**
     * 下拉选项查询
     */
    @RequestMapping("/findSelectById")
    @PreAuthorize("hasAnyAuthority('base_pay_item_bgt_eco:basepayitembgteco:list')")
    public Result findSelectById(String id) {
        BasePayItemFormSelect select = basePayItemFormService.findSelectById(id);
        return Result.succeed(select, "success");
    }

}
